package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MrBed;
import com.ruoyi.system.service.IMrBedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通道Controller
 *
 * @author ruoyi
 * @date 2023-04-01
 */
@RestController
@RequestMapping("/system/bed")
public class MrBedController extends BaseController
{
    @Autowired
    private IMrBedService mrBedService;

    /**
     * 查询通道列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:list')")
    @GetMapping("/list")
    public TableDataInfo list(MrBed mrBed)
    {
        startPage();
        List<MrBed> list = mrBedService.selectMrBedList(mrBed);
        return getDataTable(list);
    }

    /**
     * 导出通道列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:export')")
    @Log(title = "通道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MrBed mrBed)
    {
        List<MrBed> list = mrBedService.selectMrBedList(mrBed);
        ExcelUtil<MrBed> util = new ExcelUtil<MrBed>(MrBed.class);
        util.exportExcel(response, list, "通道数据");
    }

    /**
     * 获取通道详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:query')")
    @GetMapping(value = "/{bedId}")
    public AjaxResult getInfo(@PathVariable("bedId") Long bedId)
    {
        return success(mrBedService.selectMrBedByBedId(bedId));
    }

    /**
     * 新增通道
     */
    @PreAuthorize("@ss.hasPermi('system:bed:add')")
    @Log(title = "通道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MrBed mrBed)
    {
        return toAjax(mrBedService.insertMrBed(mrBed));
    }

    /**
     * 修改通道
     */
    @PreAuthorize("@ss.hasPermi('system:bed:edit')")
    @Log(title = "通道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MrBed mrBed)
    {
        return toAjax(mrBedService.updateMrBed(mrBed));
    }

    /**
     * 删除通道
     */
    @PreAuthorize("@ss.hasPermi('system:bed:remove')")
    @Log(title = "通道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bedIds}")
    public AjaxResult remove(@PathVariable Long[] bedIds)
    {
        return toAjax(mrBedService.deleteMrBedByBedIds(bedIds));
    }
}
